x86/pv: Fix multiple bugs with SEGBASE_GS_USER_SEL
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 31 Aug 2020 11:18:42 +0000 (12:18 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 31 Aug 2020 13:21:46 +0000 (14:21 +0100)
commitafe018e041ec112d90a8b4e6ed607d22aa06f280
treed53cf4044f552dafa051a5767b6001e9249a6f77
parente46474278a0e87e2b32ad5dd5fc20e8d2cb0688b
x86/pv: Fix multiple bugs with SEGBASE_GS_USER_SEL

The logic takes the segment selector unmodified from guest context.  This
allowed the guest to load DPL0 descriptors into %gs.  Fix up the RPL for
non-NUL selectors to be 3.

Xen's context switch logic skips saving the inactive %gs base, as it cannot be
modified by the guest behind Xen's back.  This depends on Xen caching updates
to the inactive base, which is was missing from this path.

The consequence is that, following SEGBASE_GS_USER_SEL, the next context
switch will restore the stale inactive %gs base, and corrupt vcpu state.

Rework the hypercall to update the cached idea of gs_base_user, and fix the
behaviour in the case of the AMD NUL selector bug to always zero the segment
base.

Reported-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/x86_64/mm.c